﻿if (document.querySelector('.download-core-box') !== null) {
    var ele = document.querySelectorAll('.bg')
    for (var e = 0; e < ele.length; e++) {
        ele[e].addEventListener('mouseover', function (event) {
            var siblings = $(this).siblings();
            for (var i = 0; i < siblings.length; i++) {
                var clazz = siblings[i].getAttribute('class');
                if (clazz !== null) {
                    if (clazz.indexOf('download') >= 0) {
                        $(siblings[i]).stop(false, false);
                        $(siblings[i]).animate({
                            top: '-65px'
                        })
                    }
                }
            }
        })
        ele[e].addEventListener('mouseleave', function (event) {
            var siblings = $(this).siblings();
            for (var i = 0; i < siblings.length; i++) {
                var clazz = siblings[i].getAttribute('class');
                if (clazz !== null) {
                    if (clazz.indexOf('download') >= 0) {
                        $(siblings[i]).stop(false, false);
                        $(siblings[i]).animate({
                            top: '0'
                        })
                    }
                }
            }
        })
    }
}

if (document.querySelector('.download-list') !== null) {
    //软件下载列表页
    toggleShow();
    document.querySelector('.download-list-header .menu ul').addEventListener('click', function (e) {
        var data = e.target.parentElement.getAttribute('data-id');
        if (data !== null) {
            if (data === '1') {
                document.querySelector('.all-list-content').style.display = 'inline-block'
                document.querySelector('.download-list-content').style.display = 'none'
                document.querySelector('.data-list-content').style.display = 'none'
            } else if (data === '2') {
                document.querySelector('.all-list-content').style.display = 'none'
                document.querySelector('.download-list-content').style.display = 'inline-block'
                document.querySelector('.data-list-content').style.display = 'none'
            } else if (data === '3') {
                document.querySelector('.all-list-content').style.display = 'none'
                document.querySelector('.download-list-content').style.display = 'none'
                document.querySelector('.data-list-content').style.display = 'inline-block'
            }
        }

    })
    clickToggleClass(document.querySelector('.download-list-content .list-second-level'), "A", "active")
    var aTab = document.querySelectorAll('.download-list-content .position span a');
    for (var i = 0; i < aTab.length; i++) {
        aTab[i].addEventListener('click', function (e) {
            var id = e.target.getAttribute('data-id');
            if (id == 0) {
                document.querySelector('.list-second-level').style.display = 'none'
            }else{
                document.querySelector('.list-second-level').style.display = 'block'
            }
        })
    }

}

if (document.querySelector('.download-details') !== null) {
    //软件下载详情页
    toggleShow();
}

function toggleShow() {
    //热门推荐鼠标移动切换
    clickToggleClass(document.querySelector('.recommend ul'), 'LI', 'active')
    var li = document.querySelectorAll('.recommend ul li');
    for (var i = 0; i < li.length; i++) {
        li[i].addEventListener('mouseover', function (e) {
            var ele = e.target
            if (ele.tagName === "LI") {
                ele.click();
            }
        })
    }
    document.querySelector('.recommend').addEventListener('mouseleave', function (e) {
        var ele = document.querySelector('.recommend ul .active');
        if (ele !== null) {
            ele.setAttribute('class', '');
        }
    })
}

function clickToggleClass(ele, tagName, className) {
    var child = ele.children;
    var clazz;
    for (var i = 0, len = child.length; i < len; i++) {
        if (child[i].tagName === tagName) {
            child[i].addEventListener('click', function (event) {
                for (var j = 0; j < len; j++) {
                    if (child[j].getAttribute("class") !== null) {
                        clazz = child[j].getAttribute("class");
                        if (clazz.length <= className.length) {
                            clazz = clazz.replace(className, '');
                            child[j].setAttribute("class", clazz);
                        } else {
                            clazz = clazz.replace((" " + className), '');
                            child[j].setAttribute("class", clazz);
                        }
                    }
                }
                if (this.getAttribute("class") !== null) {
                    this.setAttribute("class", (this.getAttribute("class") + " " + className))
                } else {
                    this.setAttribute("class", className);
                }
            })
        }
    }
}